extends partial/layout

block content
  .sl-message(style="display:none;")
    .sl-message-notice
      .sl-message-notice-content
        .sl-message-custom-content
          span
  
  header
    .wrap
      a.home(href='/')= _config_('title')
  section.wrap
    .menu
      - if(access)
        .form-group
          a.btn.btn-success(href='?a=export',target='_blank')= __('export')
          a.btn.btn-success(href='/manage/shell',target='_blank') Shell
          form.form-horizontal(style="display:inline-block;padding:5px;",method='post',action="/manage/api")
            input(type='hidden',name='a',value='clear_cache')
            button.btn.btn-danger= __('clear_cache')
          form.form-horizontal(style="display:inline-block;padding:5px;",method='post',action="/manage/api")
            input(type='hidden',name='a',value='reboot')
            button.btn.btn-danger= __('reboot')
          form.form-horizontal(style="display:inline-block;padding:5px;",method='post',action="/manage/api")
            input(type='hidden',name='a',value='signout')
            button.btn.btn-danger= __('signout')
        .panel.panel-default
          .panel-heading
            span= __("general")
          .panel-body
            form.form-horizontal(method='post',action="/manage/api")
              input(type='hidden',name='a',value='cfg')
              .form-group
                .col-sm-4
                  label= __('language')
                .col-sm-8
                  select.form-control(name='language',value=config.language)
                    option(value='', selected=config.language=='' ? 'selected' : null)= __('自动')
                    option(value='zh-CN', selected=config.language=='zh-CN' ? 'selected' : null)= __('简体中文')
                    option(value='zh-TW', selected=config.language=='zh-TW' ? 'selected' : null)= __('繁體中文')
                    option(value='en-US', selected=config.language=='en-US' ? 'selected' : null)= __('English')
              .form-group
                .col-sm-4
                  label= __('theme')
                .col-sm-8
                  select.form-control(name='theme',value=config.theme)
                    each i in config.themes
                      option(value=i, selected=i==config.theme ? 'selected' : null)= i
              .form-group
                .col-sm-4
                  label= __('index_enable')
                .col-sm-8
                  select.form-control(name='index_enable',value=config.index_enable,required)
                    option(value='1', selected=config.index_enable==1 ? 'selected' : null)= __('enable')
                    option(value='0', selected=config.index_enable==0 ? 'selected' : null)= __('disable')
              .form-group
                .col-sm-4
                  label= __('preview_enable')
                .col-sm-8
                  select.form-control(name='preview_enable',value=config.preview_enable,required)
                    option(value='1', selected=config.preview_enable==1 ? 'selected' : null)= __('enable')
                    option(value='0', selected=config.preview_enable==0 ? 'selected' : null)= __('disable')
              .form-group
                .col-sm-4
                  label= __('readme_enable')
                .col-sm-8
                  select.form-control(name='readme_enable',value=config.readme_enable,required)
                    option(value='1', selected=config.readme_enable==1 ? 'selected' : null)= __('enable')
                    option(value='0', selected=config.readme_enable==0 ? 'selected' : null)= __('disable')
              .form-group
                .col-sm-4
                  label= __('anonymous_uplod_enable')
                .col-sm-8
                  select.form-control(name='anonymous_uplod_enable',value=config.anonymous_uplod_enable,required)
                    option(value='1', selected=config.anonymous_uplod_enable==1 ? 'selected' : null)= __('enable')
                    option(value='0', selected=config.anonymous_uplod_enable==0 ? 'selected' : null)= __('disable')
              .form-group
                .col-sm-4
                  label= __('anonymous_download')
                .col-sm-8
                  input.form-control(type='text', name='anonymous_download' , value=config.anonymous_download,placeholder=__('anonymous_download_placeholder'))
              hr
              .form-group
                .col-sm-4
                  label= __('proxy_enable')
                .col-sm-8
                  select.form-control(name='proxy_enable',value=config.proxy_enable,required)
                    option(value='1', selected=config.proxy_enable==1 ? 'selected' : null)= __('enable')
                    option(value='0', selected=config.proxy_enable==0 ? 'selected' : null)= __('disable')
              .form-group
                .col-sm-4
                  label= __('proxy_paths')
                .col-sm-8
                  input.form-control(type='text', name='proxy_paths' , value=config.proxy_paths.join(','),placeholder=__('ignore_paths_placeholder'))
              .form-group
                .col-sm-4
                  label= __('proxy_server')
                .col-sm-8
                  input.form-control(type='text', name='proxy_server' , value=config.proxy_server,placeholder=__('proxy_server_placeholder'))
              hr
              .form-group
                .col-sm-4
                  label= __('max_age_dir')
                .col-sm-8
                  input.form-control(type='text', name='max_age_dir' , value=config.max_age_dir / 1000,required)
              .form-group
                .col-sm-4
                  label= __('max_age_file')
                .col-sm-8
                  input.form-control(type='text', name='max_age_file' , value=config.max_age_file / 1000,required)
              .form-group
                .col-sm-4
                  label= __('max_age_download')
                .col-sm-8
                  input.form-control(placeholder=__('max_age_download_placeholder'),type='text', name='max_age_download' , value=config.max_age_download / 1000,required)
              .form-group
                .col-sm-4
                  label= __('ignore_file_extensions')
                .col-sm-8
                  input.form-control(type='text', name='ignore_file_extensions' , value=config.ignore_file_extensions,placeholder=__('ignore_file_extensions_placeholder'))
              .form-group
                .col-sm-4
                  label= __('ignore_paths')
                .col-sm-8
                  input.form-control(type='text', name='ignore_paths' , value=config.ignore_paths.__root__.join(','),placeholder=__('ignore_paths_placeholder'))
              hr
              .form-group
                .col-sm-4
                  label= __('webdav_path')
                .col-sm-8
                  input.form-control(type='text', name='webdav_path' , value=config.webdav_path,required)
              .form-group
                .col-sm-4
                  label= __('smb_server_enable')
                .col-sm-8
                  select.form-control(name='smb_server_enable',value=config.smb_server_enable,required)
                    option(value='1', selected=config.smb_server_enable==1 ? 'selected' : null)= __('enable')
                    option(value='0', selected=config.smb_server_enable==0 ? 'selected' : null)= __('disable')
                           .form-group
                .col-sm-4
                  label= __('smb_server_port')
                .col-sm-8
                  input.form-control(type='text', name='smb_server_port' , value=config.smb_server_port,required)
              .form-group
                .col-sm-4
                  label= __('smb_anonymous_enable')
                .col-sm-8
                  select.form-control(name='smb_anonymous_enable',value=config.smb_anonymous_enable,required)
                    option(value='1', selected=config.smb_anonymous_enable==1 ? 'selected' : null)= __('enable')
                    option(value='0', selected=config.smb_anonymous_enable==0 ? 'selected' : null)= __('disable')
              .form-group
                .col-sm-4
                  label= __('ocr_server')
                .col-sm-8
                  input.form-control(type='text', name='ocr_server' , value=config.ocr_server,placeholder=__('ocr_server_placeholder'))
              .form-group
                .col-sm-4
                  label= __('custom_style')
                .col-sm-8
                  textarea.form-control(name='custom_style')
                    | #{config.custom_style}
              .form-group
                .col-sm-4
                  label= __('custom_script')
                .col-sm-8
                  textarea.form-control(name='custom_script')
                    | #{config.custom_script}
              .form-group.text-center
                button.btn.btn-default(type='submit')= __('save')
        .panel.panel-default
          .panel-heading
            span= __("plugin_option")
          .panel-body
            form.form-horizontal(method='post',action="/manage/api")
              input(type='hidden',name='a',value='plugin_option')
              each i in config.plugin_option
                .form-group
                  .col-sm-4
                    label= i.value.label
                  .col-sm-8
                    -if(i.value.options)
                      select.form-control(name=i.key,value=i.value.value)
                        each j in i.value.options
                          option(value=j.value, selected=j.value==i.value.value ? 'selected' : null)= j.label
                    -else
                      input.form-control(type='text',placeholder=i.value.placeholder, name=i.key , value=i.value.value)
              .form-group.text-center
                button.btn.btn-default(type='submit')= __('save')
        .panel.panel-default
          .panel-heading= __('token')
          .panel-body
            form.form-horizontal(method='post',action="/manage/api")
              input(type='hidden',name='a',value='token')
              .form-group
                .col-sm-12
                  input.form-control(type='text', name='token' , placeholder=__('new_token'),required)
              .form-group.text-center
                button.btn.btn-default(type='submit')= __('save')
        .panel.panel-default
          .panel-heading= __('site_title')
          .panel-body
            form.form-horizontal(method='post',action="/manage/api")
              input(type='hidden',name='a',value='title')
              .form-group
                .col-sm-12
                  input.form-control(type='text', name='title' , value=config.title , placeholder=__('site_title'),required)
              .form-group.text-center
                button.btn.btn-default(type='submit')= __('save')
        .panel.panel-default
          .panel-heading
            span= __('virtual_path')
            a.create-path(style='float:right;')= __('add')
          .panel-body
            form.form-horizontal#j_path(method='post',action="/manage/api")
              .group-path
                input(type='hidden',name='a',value='path')
                each i in config.path
                  .form-group.item
                    .col-sm-3
                      select.form-control(name='vendor', value=(i.path.match(/^.*(?=\:\/\/)/) || [''])[0],placeholder=__('type'),required)
                        each vendor in vendors
                          option(value=vendor.protocol, selected=i.path.indexOf(vendor.protocol+':')>=0 ? 'selected' : null) #{vendor.label}
                    .col-sm-2
                      input.form-control(type='text', name='name', value=i.name,placeholder=__('name'),required)
                    .col-sm-6
                      input.form-control(type='text', name='path', value=i.path.replace(/^.*?\:/,''),placeholder=__('input_path_placeholder'))
                    .col-sm-1
                      button.btn.btn-default.remove-path(type='button') -
              .form-group.text-center
                  button.btn.btn-default(type='submit')= __('save')
            
      - else
        div.auth
          h3= __("manage")
          div
            form.form-horizontal(method='post',action="/manage/api")
              input(type='hidden',name='a',value='signin')
              .form-group
                input.sl-input#j_token(type='password', name='token', placeholder=__('input_token'))
              button.sl-button.btn-primary#signin(type="submit")= __('signin')
  script(src='https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js')
  script(src='https://cdn.bootcdn.net/ajax/libs/jquery.form/4.3.0/jquery.form.min.js')
  script(src='https://cdn.bootcdn.net/ajax/libs/instantclick/3.1.0/instantclick.min.js')
  script('data-no-instant').
    InstantClick.init('mousedown')
    $(function(){
      /*
      $('#signin').on('click' , function(){
        location.href = '/manage/'+ $('#j_token').val()
      })

      $('#j_token').on('keypress' , function(e){
        if(e.keyCode == "13"){
          location.href = '/manage/'+ $('#j_token').val()
        }
      })
    */
      var item
      if($('.item').length){
        item = $('.item:first').clone()
        item.find('input').val('')
      }
      $('body').on('click','.create-path' , function(){
        $('.group-path').append( item.clone() )
      })
      .on('click' ,'.remove-path' , function(){
        $(this).parents('.item').remove()
      })

      function showMsg(m){
        $('.sl-message span').html(m)
        $('.sl-message').fadeIn(50)
        setTimeout(function(){
          $('.sl-message').fadeOut(1000)
        },2000)

      }
      $('form').ajaxForm({success:function(resp){
        if(resp && resp.message){
          showMsg(resp.message)
        }
        
        if( 
          (resp.a =='signin' || resp.a == 'token' || resp.a == 'signout') && resp.status == 0
        ){
          location.reload()
        }else if(resp.status != 0){
          location.reload()
        }
      }})
    })
    
    

  include partial/footer